﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FSImport.aspx.cs" Inherits="MaluJg.web.ProcessInput.FSImport" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>导入农民股金</title>
    <link href="../ThreeStyle/Css/Css.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../DatePicker/WdatePicker.js"></script>

    <base target="_self" />

    <script type="text/javascript">
        function down() {
            var ddl = document.getElementById('slTemp');

            var sel = ddl.options[ddl.selectedIndex].value;
            var url = '';
            switch (sel) {
                case 'fshare': url = 'TemplateFile/农民股金.xls'; break;
                case 'fbooth': url = 'TemplateFile/摊位.xls'; break;
                case 'fhuafei': url = 'TemplateFile/化肥.xls'; break;
                case 'fcold': url = 'TemplateFile/冷库.xls'; break;
                case 'fgreen': url = 'TemplateFile/大棚.xls'; break;
                case 'fmembrane': url = 'TemplateFile/银灰膜.xls'; break;
                case 'fpackage': url = 'TemplateFile/包装箱.xls'; break;
                case 'sliving': url = 'TemplateFile/低保.xls'; break;
                case 'ssick': url = 'TemplateFile/大病扶持.xls'; break;
                case 'sstudy': url = 'TemplateFile/助学救助.xls'; break;
                case 'sdeformity': url = 'TemplateFile/重残无业.xls'; break;
                case 'sothers': url = 'TemplateFile/其他救助.xls';
                    break;

            }
            if (url != '')
                window.open(url);

        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="PopupDiv">
        <table class="Table" cellpadding="3" cellspacing="1" width="100%">
            <tr>
                <td class="TableItem" align="right" style="width: 10%;">
                    请导入：
                </td>
                <td align="left">
                    <table style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px;
                        border-right-width: 0px">
                        <tr>
                            <td style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px;
                                border-right-width: 0px">
                                <div id="uploadImageDiv">
                                    <input type="file" id="attatchFile" class="TextboxRead" name="attatchFile" />
                                </div>
                            </td>
                            <td style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px;
                                border-right-width: 0px">
                                <div>
                                    <input type="button" id="uploadButton" class="Button01" onclick="uploadImage();"
                                        runat="server" value="上传" /></div>
                                <span id="uploadMessage" style="border: 1px solid #cccccc; color: Red;"></span>
                            </td>
                            <td>
                                选择年份:
                            </td>
                            <td>
                                <asp:TextBox runat="server" ID="tbYear" onclick="WdatePicker({dateFmt:'yyyy'})" CssClass="Textbox01"></asp:TextBox>
                            </td>
                            <td>
                                选择模板<select id="slTemp" name="slTemp">
                                    <option value="fshare" selected="selected">农民股金</option>
                                    <option value="fbooth">摊位</option>
                                    <option value="fhuafei">有机肥</option>
                                    <option value="fcold">冷库</option>
                                    <option value="fgreen">大棚</option>
                                    <option value="fmembrane">银灰膜</option>
                                    <option value="fpackage">包装箱</option>
                                    <option value="sliving">低保</option>
                                    <option value="ssick">大病扶持</option>
                                    <option value="sstudy">助学救助</option>
                                    <option value="sdeformity">重残无业</option>
                                    <option value="sothers">其他救助</option>
                                </select>
                                <a href="#" onclick="down()" style="color: Blue;">下载</a>
                            </td>
                            <td style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px;
                                border-right-width: 0px">
                                <div id="processDiv" style="display: none; color: #660066; font-family: Arial">
                                    <img src="../images/loading2.gif" alt="uploading" style="width: 18px; height: 18px" />数据导入中<span
                                        id="fileName" />
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <div style="text-align: center; margin-top: 10px;">
            <fieldset style="width: 90%; text-align: left; height: 65px; vertical-align: bottom;">
                <legend>本次导入结果</legend><span id="pbFileUpload"></span>
            </fieldset>
            <div style="margin: 10px;">
            </div>
            <fieldset style="width: 90%; text-align: left;">
                <legend>历史导入记录</legend>
                <iframe src="GetStatus.aspx?InputDataType=Employee" id="ifrmGetStatus" style="width: 100%;
                    border: 0px; height: 350px;" scrolling="no" allowtransparency="true" frameborder="0">
                </iframe>
            </fieldset>
        </div>
    </div>
    </form>
    <div style="display: none;">
        <iframe name="uploadResponse"></iframe>
        <form id="uploadForm" action="FSInputData.aspx?t=<%= DateTime.Now.Ticks %>" target="uploadResponse"
        method="post" enctype="multipart/form-data">
        <input type="file" name="attatchFile" value="" />
        </form>
    </div>

    <script language="javascript">
        function formUnload() {
            try {
                var win = window.opener;
                if (win != null) {
                    win.location = win.location.href;
                }
            }
            catch (e)
		   { }
        }

        function $(id) {
            return document.getElementById(id);
        }

        var fileURL = "";

        function uploadImage() {

            var file = document.getElementById("attatchFile");
            if (file.value == "") {
                alert("请选择上传文件！");
                return;
            }
            var year = document.getElementById('tbYear').value;
            if (year == '') {
                alert('选择年份');
                return;
            }

            var uploadFormElement = document.getElementById("uploadForm");


            //显示进度条
            document.getElementById("processDiv").style.display = "block"; // the progress div

            //复制数据
            uploadFormElement.removeChild(uploadFormElement.attatchFile);
            uploadFormElement.appendChild(file);
            document.getElementById("uploadImageDiv").innerHTML = '<input type="file" id="attatchFile" name="attatchFile" />';

            //提交数据
            var ddl = document.getElementById('slTemp');

            var sel = ddl.options[ddl.selectedIndex].value;
            uploadFormElement.action = "FSInputData.aspx?formtype=" + sel + "&year=" + year + "&t=<%= DateTime.Now.Ticks %>";

            uploadFormElement.submit();
        }

        function uploadImageResponse(response) {

            document.getElementById("processDiv").style.display = "none"; // hide progresss div
            var errLabel = document.getElementById("uploadMessage");
            errLabel.innerHTML = "";
            window.eval("var k=" + response);
            if (k.status == 1)
                errLabel.innerHTML = k.message;
            else {
                fileURL = k.message;
            }
            SetStatus();
            ifrmGetStatus.window.location.reload();

        }

        function setFileName(control) {
            var fileName = control.value;
            var strArr = fileName.split("\\");
            fileName = strArr[strArr.length - 1];
            fileName = fileName.substring(0, fileName.lastIndexOf("."));
            $("custFileName").value = fileName;
        }

        function SetStatus() {
            JiaDing.Platform.GetStatus(returnFun);
            function returnFun(result) {
                var _result = result.value;
                if (_result.ErrorCode == -1) {
                    alert(_result.Message);
                }
                else {
                    if (_result.Value) {
                        var UploadClass = _result.Value;
                        var showMsg = "";
                        if (UploadClass.ErrDes != "") {
                            alert(UploadClass.ErrDes);
                        }

                        showMsg += "共：" + (UploadClass.RightCount + UploadClass.ErrCount) + "条记录；</br>";
                        showMsg += "成功：" + UploadClass.RightCount + " ；</br>";
                        showMsg += "失败：" + UploadClass.ErrCount;
                        $("pbFileUpload").innerHTML = showMsg;
                    }
                }
            }
        }
        function setFormType() {
            var f = '<%=FormType %>';
            if (f != '') {
                var ddl = document.getElementById('slTemp');
                ddl.value = f;
            }
        }
        setFormType();
    </script>

</body>
</html>
